home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Freelog 125
/
Freelog_MarsAvril2015_No125.iso
/
Musique
/
Quod Libet
/
quodlibet-3.3.0-installer.exe
/
bin
/
quodlibet
/
qltk
/
searchbar.pyc
(
.txt
)
< prev
next >
Wrap
Python Compiled Bytecode
|
2014-12-31
|
9KB
|
201 lines
# Source Generated with Decompyle++
# File: in.pyc (Python 2.7)
import os
from gi.repository import Gtk, GObject, GLib
from quodlibet import config
from quodlibet import const
from quodlibet.parse import Query
from quodlibet.qltk.cbes import ComboBoxEntrySave
from quodlibet.qltk.ccb import ConfigCheckMenuItem
from quodlibet.qltk.x import SeparatorMenuItem
from quodlibet.util import limit_songs, DeferredSignal
class SearchBarBox(Gtk.HBox):
'''
A search bar widget for inputting queries.
signals:
query-changed - a parsable query string
focus-out - If the widget gets focused while being focused
(usually for focusing the songlist)
'''
__gsignals__ = {
'query-changed': (GObject.SignalFlags.RUN_LAST, None, (object,)),
'focus-out': (GObject.SignalFlags.RUN_LAST, None, ()) }
timeout = 400
def __init__(self, filename = None, completion = None, accel_group = None):
super(SearchBarBox, self).__init__(spacing = 6)
if filename is None:
filename = os.path.join(const.USERDIR, 'lists', 'queries')
combo = ComboBoxEntrySave(filename, count = 8, validator = Query.is_valid_color, title = _('Saved Searches'), edit_title = _('Edit saved searches...'))
self._SearchBarBox__deferred_changed = DeferredSignal(self._SearchBarBox__filter_changed, timeout = self.timeout, owner = self)
self._SearchBarBox__combo = combo
entry = combo.get_child()
self._SearchBarBox__entry = entry
if completion:
entry.set_completion(completion)
self._SearchBarBox__sig = combo.connect('text-changed', self._SearchBarBox__text_changed)
entry.connect('clear', self._SearchBarBox__filter_changed)
entry.connect('backspace', self._SearchBarBox__text_changed)
entry.connect('populate-popup', self._SearchBarBox__menu)
entry.connect('activate', self._SearchBarBox__filter_changed)
entry.connect('activate', self._SearchBarBox__save_search)
entry.connect('focus-out-event', self._SearchBarBox__save_search)
entry.set_placeholder_text(_('Search'))
entry.set_tooltip_text(_('Search your library, using free text or QL queries'))
combo.enable_clear_button()
self.pack_start(combo, True, True, 0)
if accel_group:
(key, mod) = Gtk.accelerator_parse('<ctrl>L')
accel_group.connect(key, mod, (0,), (lambda : entry.mnemonic_activate(True)))
for child in self.get_children():
child.show_all()
def set_text(self, text):
'''Set the text without firing any signals'''
self._SearchBarBox__deferred_changed.abort()
self._SearchBarBox__inhibit()
self._SearchBarBox__entry.set_text(text)
self._SearchBarBox__uninhibit()
def get_text(self):
'''Get the active text as unicode'''
return self._SearchBarBox__entry.get_text().decode('utf-8')
def changed(self):
'''Triggers a filter-changed signal if the current text
is a parsable query
'''
self._SearchBarBox__filter_changed()
def __inhibit(self):
self._SearchBarBox__combo.handler_block(self._SearchBarBox__sig)
def __uninhibit(self):
self._SearchBarBox__combo.handler_unblock(self._SearchBarBox__sig)
def __menu(self, entry, menu):
sep = SeparatorMenuItem()
sep.show()
menu.prepend(sep)
cb = ConfigCheckMenuItem(_('Search after _typing'), 'settings', 'eager_search', populate = True)
cb.set_tooltip_text(_('Show search results after the user stops typing.'))
cb.show()
menu.prepend(cb)
def __mnemonic_activate(self, label, group_cycling):
widget = label.get_mnemonic_widget()
if widget.is_focus():
self.emit('focus-out')
return True
def __save_search(self, entry, *args):
if args and not config.getboolean('settings', 'eager_search'):
return None
text = None.get_text().strip()
if text and Query.is_parsable(text):
self._SearchBarBox__inhibit()
self._SearchBarBox__combo.prepend_text(text)
self._SearchBarBox__combo.write()
self._SearchBarBox__uninhibit()
def __filter_changed(self, *args):
self._SearchBarBox__deferred_changed.abort()
text = self.get_text()
if Query.is_parsable(text):
GLib.idle_add(self.emit, 'query-changed', text)
def __text_changed(self, *args):
if self._SearchBarBox__combo.get_active() != -1:
self._SearchBarBox__filter_changed()
return None
if not None.getboolean('settings', 'eager_search'):
return None
None._SearchBarBox__deferred_changed()
class LimitSearchBarBox(SearchBarBox):
'''A version of `SearchBarBox` that allows specifying the limiting and
weighting of a search.'''
class Limit(Gtk.HBox):
__gsignals__ = {
'changed': (GObject.SignalFlags.RUN_LAST, None, ()) }
def __init__(self):
super(LimitSearchBarBox.Limit, self).__init__(spacing = 3)
label = Gtk.Label(label = _('_Limit:'))
self.pack_start(label, True, True, 0)
self._Limit__limit = limit = Gtk.SpinButton()
self._Limit__limit.connect('value-changed', self._Limit__changed)
limit.set_numeric(True)
limit.set_range(0, 9999)
limit.set_increments(5, 100)
label.set_mnemonic_widget(limit)
label.set_use_underline(True)
self.pack_start(limit, True, True, 0)
self._Limit__weight = Gtk.CheckButton(label = _('_Weight'), use_underline = True)
self._Limit__weight.connect('toggled', self._Limit__changed)
self.pack_start(self._Limit__weight, True, True, 0)
for child in self.get_children():
child.show()
def __changed(self, *args):
self.emit('changed')
def value(self):
return self._Limit__limit.get_value_as_int()
value = property(value)
def weighted(self):
return self._Limit__weight.get_active()
weighted = property(weighted)
def __init__(self, show_limit = False, *args, **kwargs):
super(LimitSearchBarBox, self).__init__(*args, **kwargs)
self._LimitSearchBarBox__limit = self.Limit()
self.pack_start(self._LimitSearchBarBox__limit, False, True, 0)
self._LimitSearchBarBox__limit.set_no_show_all(not show_limit)
self._LimitSearchBarBox__limit.connect('changed', self._LimitSearchBarBox__limit_changed)
def __limit_changed(self, *args):
self.changed()
def limit(self, songs):
if self._LimitSearchBarBox__limit.get_visible():
return limit_songs(songs, self._LimitSearchBarBox__limit.value, self._LimitSearchBarBox__limit.weighted)
return None
def toggle_limit_widgets(self, button):
'''Toggles the visibility of the limit widget according to `button`'''
if button.get_active():
self._LimitSearchBarBox__limit.show()
else:
self._LimitSearchBarBox__limit.hide()
self.changed()